package com.example.demo.model;

import com.example.demo.enums.ResultCode;
import lombok.Data;

@Data
public class Result {

    //这里状态码用的枚举
     ResultCode code;  //业务状态码：1-成功  -1-失败；0-未登录；如果状态码为200，total为0，代表数据库为空了，如果状态码为400，total为0，后端出错了
    String erMsg;  //错误信息
    Object data;

    public static Result success(Object listInfo){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setErMsg("");
        result.setData(listInfo);
        return result;
    }
    public static Result unlogin(){
        Result result = new Result();
        result.setCode(ResultCode.UNLOGIN);
        result.setErMsg("用户未登录");
        result.setData(null);
        return result;
    }
    public static Result fail(Exception e)
    {
        Result result = new Result();
        result.setCode(ResultCode.FAIL);
        result.setErMsg("错误原因为："+e);
        result.setData(null);
        return result;
    }
}
